﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using BASE;

public partial class Admin_thoikhoabieu : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Utils.getIntSession("userid") == 0)
        {
            Response.Redirect("/admin/login.aspx");
        }

        //check quyen vao trang
        busMenu busM = new busMenu();
        if (!busM.checkQuyenVaoTrang(Utils.getIntSession("userid"), Constants.ADMIN_CAPNHATTHOIKHOABIEU))
        {
            ChuyenTrang();
        }

        Session["trang"] = Constants.ADMINTHOIKHOABIEU;
        if (!IsPostBack)
        {
            btn_luu.Visible = false;
        }

    }
    protected void btn_luu_Click(object sender, EventArgs e)
    {
        div_wait.Visible = true;
        busThoiKhoaBieu busTKB = new busThoiKhoaBieu();

        busTKB.update(base.ViewState["path"].ToString(), base.ViewState["path2"].ToString());
        Response.Write(base.ViewState["path2"].ToString());
        div_me.Visible = true;
        lb_me.Text = "Cập nhật thành công";
        div_wait.Visible = false;
        btn_luu.Visible = false;
        btn_up.Visible = false;


    }
    protected void btn_up_Click(object sender, EventArgs e)
    {
        List<WebControl> lst = new List<WebControl>();
        lst.Add(f);
        lst.Add(f2);
        string check = Utils.checkDataType(lst);
        if (check != "")
        {
            lb_me.Text = check;
            return;
        }
        if (!Directory.Exists(MapPath("/Data/")))
        {
            Directory.CreateDirectory(MapPath("/Data/"));
        }
        f.SaveAs(MapPath("/Data/" + "a" + Path.GetExtension(f.FileName)));
        f2.SaveAs(MapPath("/Data/" + "a2" + Path.GetExtension(f2.FileName)));
        btn_luu.Visible = true;
        base.ViewState["path"] = MapPath("/Data/" + "a" + Path.GetExtension(f.FileName));
        base.ViewState["path2"] = MapPath("/Data/" + "a2" + Path.GetExtension(f2.FileName));
    }
}